package com.bawei.lib_common.video


import com.bawei.lib_common.base.BaseApplication
import com.danikula.videocache.HttpProxyCacheServer
import java.io.File

/**
 *@author yaotianxue
 *@description 视频缓存
 *@date 2022/10/20 18:15
 */
object VideoCacheProxy {

    private var instance: HttpProxyCacheServer? = null
    private fun newProxy(): HttpProxyCacheServer? {
        try {
            return HttpProxyCacheServer.Builder(BaseApplication.instance)
                .cacheDirectory(File(BaseApplication.instance.externalCacheDir, "video-cache"))
                .build()
        } catch (e: Exception) {
            //	java.net.SocketException:socket failed: ENONET (Machine is not on the network)
            e.printStackTrace()
        }
        return null
    }

    fun get(): HttpProxyCacheServer? {
        if (instance == null) {
            synchronized(this) {
                if (instance == null) {
                    instance = newProxy()
                }
            }
        }
        return instance
    }
}